<template>
  <div class="page">
	<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">

						<div class="layui-card-body">
							<div class="layui-form" lay-filter="">

								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">会员名称</label>
									    <div class="layui-input-inline" style="width: 380px;">
									        <input type="text" name="accountName" placeholder="名称"  v-model="itemData.accountName" autocomplete="off" class="layui-input a" >
									    </div>
								  </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">手机号</label>
									    <div class="layui-input-inline" style="width: 380px;">
									        <input type="number" name="mobile" placeholder="手机号"  v-model="itemData.mobile" autocomplete="off" class="layui-input a" maxlength="11">
									    </div>
								  </div>
								</div>	
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">会员生日</label>
									    <div class="layui-input-inline" style="width: 380px;">
									        <input type="text" name="birthday" placeholder="会员生日"  v-model="birthday" autocomplete="off" class="layui-input a" maxlength="">
									    </div>
								  </div>
								</div>								
						    <div class="layui-form-item">
									<div class="layui-block">
									    <label class="layui-form-label">会员等级</label>
									    <div class="layui-input-inline" style="width: 380px;">
									     <select name="levelid" lay-filter="levelid" v-model="levelid">	
									     	 <!--<option value=''>{{item.name}}</option>-->
								         <option :value='item.id' v-for="item in levelist">{{item.name}}</option>
									     </select>
									    </div>
								  </div>
								</div>
								<div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">地址</label>
							    <div class="layui-input-block">
							      <textarea name="address" placeholder="请输入内容" class="layui-textarea" v-model="itemData.address"></textarea>
							    </div>
							 </div>
							 <div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">备注</label>
							    <div class="layui-input-block">
							      <textarea name="note" placeholder="请输入内容" class="layui-textarea" v-model="itemData.note"></textarea>
							    </div>
							 </div>	
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo" @click="confirmOk">确认</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</template>
<script>

export default {
  name: 'goodsfladd',
  data () {
    return {
    	id:'',    	
    	itemData:{},
    	birthday:'',
    	levelid:'',
    	levelname:'',
			levelist:[],	
			totalRows:"",//总数量
	    curindex:1, //页数  
	    shopId:localStorage.getItem("shopId"),
    }
  },
  mounted(){
    var _this = this;   
  	window.getdates = this.getdates;  	
  	_this.getlevel();
  },
  methods: {
		getdates:function(res){
      var _this=this;
      _this.id=res.id;
      var url="/shop/bapi/v1.9/members/"+res.id
		  ajaxRequest(url,'GET','json','',function(ret,err){
        _this.itemData=ret.data;
        _this.birthday=ret.data.birthdate;
        
      })
		},
		getlevel:function(){
			var _this=this;
			var dates={
	    		 size:100,
	    		 page:_this.curindex,	    					        
	    }
			var url="/shop/bapi/v1.9/levels"			
		  ajaxRequest(url,'GET','json',dates,function(ret,err){
        _this.levelist=ret.data.list;         
		  	_this.totalRows=ret.data.totalRows;
		  	_this.curindex=ret.data.pageNumber+1;
     })			
		},
  	confirmOk:function(){
  		var _this = this;
			var len = $(".a").length;
			for(var i = 0; i < len; i++) {
				if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
					var msg = $(".a").eq(i).attr("placeholder");
					layer.msg('请输入正确的'+msg);
					return;
				}
			}
			var level={
				id:_this.levelid,
			}
			var birthdays = getsjc(_this.birthday)			
	  	if(_this.id){
			  var hat='PUT'
				var dates={
					 realName:_this.itemData.realName,
				   birthdate:birthdays,  			 
				   payTypeId:'-1',
				   sex:_this.itemData.sex,
				   mobile:_this.itemData.mobile,
				   idCard:0,
				   shopId:_this.itemData.shopId,
				   address:_this.itemData.address,
				   beforeLevelId:'',//升级前会员等级
				   level:level, 
				   note:_this.itemData.note,
				}
			}else{
				var hat='POST'
				var dates={
					  realName:_this.itemData.realName,
					  birthdate:birthdays,  // "2020-04-27T03:24:19.207Z",			 
					  payTypeId:'-1',//现金支付
					  sex: 0,
				    mobile:_this.itemData.mobile,					 
					  idCard:0,
					  shopId:_this.shopId,
					  address:_this.itemData.address,
					  beforeLevelId:'',//升级前会员等级	
					  level:level, 
					  note:_this.itemData.note,	
				}
			}
			//alert(JSON.stringify(dates))
			var url="/crm/bapi/v1.9/member"	       
	    ajaxRequest(url,hat,'json',dates,function(ret,err){
			  layer.msg("操作成功");
			  setTimeout(function(){
			  	var index = parent.layer.getFrameIndex(window.name);
			    parent.layer.close(index);
		      parent.location.reload();
	      },1000)
			})
  	}
  },
  updated:function(){
  	var _this=this;
		layui.use('form', function(){
		  var form = layui.form;
		  form.render();
		  form.on('select(levelid)', function(data){
				 	_this.levelid=data.value;				 
			});
		});
  },
}
</script>
<style scoped>
</style>
